﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[assembly: TagPrefix("WebModel", "webModel")]
namespace ActionModel.WebModel
{
	[DefaultProperty("value")]
	[ToolboxData("<{0}:ValidInput runat=server></{0}:ValidInput>")]
	public class ValidInput : WebControl
	{
		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public string value
		{
			get
			{
				String s = (String)ViewState["value"];
				return ((s == null) ? String.Empty : s);
			}
			set
			{
				ViewState["value"] = value;
			}
		}

		public InputType type { get; set; }
		public string FieldName { get; set; }
		public string FieldLabel { set; get; }
		public string FieldTitle { set; get; }

		protected override HtmlTextWriterTag TagKey
		{
			get
			{
				return HtmlTextWriterTag.Div;
			}
		}

		protected override void RenderContents(HtmlTextWriter output)
		{
			output.WriteLine("<label for=\"" + FieldName + "\">" + FieldLabel + "：</label>");
			output.WriteLine("<input type=\"" + type + "\" value=\"" + value + "\" id=\"" + FieldName + "\" name=\"" + FieldName + "\" title=\"" + (FieldTitle == null ? FieldLabel : FieldTitle) + "\" />");
			output.Write("<span id=\"" + FieldName + "-Tips\"></span>");
		}

		public enum InputType
		{
			text,
			password
		}
	}
}
